// https://api.apidoc.doyzheng.com/user/get
// https://api.apidoc.doyzheng.com/project/list
// https://api.apidoc.doyzheng.com/project/join-list
// https://api.apidoc.doyzheng.com/category/list
// https://api.apidoc.doyzheng.com/dictionary/detail
// https://api.apidoc.doyzheng.com/api/list

// yl-cli login 19137804785 li111111;

const HOST = 'https://api.apidoc.doyzheng.com';
import axios from 'axios';
import { cache } from "../utils/cache.js";

function exec(cmds = []) {
    const acc = cmds.shift();
    const pass = cmds.shift();
    acc && cache('account', acc);
    pass && cache('password', pass);

    const account = cache('account');
    const password = cache('password');
    cache('debug') && console.log('登录');
    return axios.post(`${HOST}/login/account`, {
        account: account,
        password: password
      })
      .then(({ data: { data: { token } } }) => {
        cache('debug') && console.log(token);
        cache('token', token);
      })
      .catch((err) => {
        console.error(err);
        cache('debug') && console.log('账号:' + account);
        cache('debug') && console.log('密码:' + password);
      });
}

export {
    exec
}
